//
//  NSThread_VC.m
//  DXC
//
//  Created by TOPTEAM on 2017/5/8.
//  Copyright © 2017年 TOPTEAM. All rights reserved.
//

#import "NSThread_VC.h"
#import "KKThread.h"

@interface NSThread_VC ()

@end

@implementation NSThread_VC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor=[UIColor whiteColor];
    self.title=@"NSThread";

}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self createThread3];
    
}
/*
 第三种创建线程的方式
 特点:默认开启线程
 */
-(void)createThread3
{
    
    [self performSelectorInBackground:@selector(run:) withObject:@"后台线程"];
}

/*
 第二种创建线程的方式
 特点:默认开启线程
 */
-(void)createThread2
{
    /*
     第一个参数:选择器,调用哪个方法
     第二个参数:目标对象
     第三个参数:前面方法需要传递的参数
     */
    [NSThread detachNewThreadSelector:@selector(run:) toTarget:self withObject:@"wendingding"];
    
}
/*
 第一种创建线程的方式
 特点:需要调用start方法开启线程
 */
-(void)createThread1
{
    //    NSLog(@"%@",[NSThread currentThread]);
    //创建线程
    /*
     第一个参数:目标对象
     第二个参数:选择器,调用哪个方法
     第三个参数:前面方法需要传递的参数
     */
    //    NSThread *thread1 = [[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil];
    //    //设置基本属性
    //    thread1.name = @"线程1";
    //
    //    //线程优先级
    //    [thread1 setThreadPriority:1.0];
    //
    //    //开启线程
    //    [thread1 start];
    //
    //    NSThread *thread2 = [[NSThread alloc]initWithTarget:self selector:@selector(run) object:nil];
    //        thread2.name = @"线程2";
    //    [thread2 setThreadPriority:0.1];
    //    //开启线程
    //    [thread2 start];
    
    KKThread *thread3 = [[KKThread alloc]initWithTarget:self selector:@selector(run) object:nil];
    thread3.name = @"线程3";
    
    //开启线程
    [thread3 start];
}
-(void)run:(NSString *)str
{
    
    for (NSInteger i = 0; i<1000; i++) {
        NSLog(@"-%zd--run---%@--%@",i,[NSThread currentThread],str);
    }
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
